<template>
  <div class="report">
    <el-table
      :data="reportData"
      style="width: 100%;margin:0px auto"
      :header-cell-style="{ background: '#f5f5f6', color: '#9EA0A5' }"
    >
      <el-table-column type="index" label="序号" width="80"></el-table-column>
      <el-table-column prop="startTime" label="离线开始时间"></el-table-column>
      <el-table-column prop="endTime" label="离线结束时间"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scoped">
          <el-button type="warning" plain @click="showTimeCure(scoped.row)"
            >查看此时段运行曲线</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        @size-change="handleSizeShopChange"
        @current-change="handleCurrentShopChange"
        :current-page="reporForm.pageNumber"
        :page-sizes="[2, 4, 6, 8, 10]"
        :page-size="reporForm.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { historyCurveList } from "../../utils/api";
export default {
  data() {
    return {
      reportData: [],
      reporForm: {
        pageSize: 10,
        pageNumber: 1,
        deviceId: ""
      },
      total: 0,
      deviceId: ""
    };
  },
  methods: {
    // 获取历史记录列表
    getOffLineList() {
      const params = {
        pageNumber: this.reporForm.pageNumber,
        pageSize: this.reporForm.pageSize,
        deviceId: this.reporForm.deviceId
      };
      this.postRequest(historyCurveList, this.reporForm).then(res => {
        if (res.code == 200) {
          this.reportData = res.data.data;
          this.total = res.data.count;
        }
      });
    },
    // 分页
    // 选择每页多少条
    handleSizeShopChange(val) {
      this.reporForm.pageSize = val;
      this.getOffLineList();
    },
    // 选择第几页
    handleCurrentShopChange(val) {
      this.reporForm.pageNumber = val;
      this.getOffLineList();
    },
    showTimeCure(data) {
      this.$router.push("/Offcurve");
      window.sessionStorage.setItem("OffInfo", JSON.stringify(data));
    }
  },
  created() {
    const deviceInfo = JSON.parse(
      window.sessionStorage.getItem("facilityData")
    );
    // 安
    if (window.sessionStorage.getItem("deviceId") == null) {
      this.reporForm.deviceId = deviceInfo.id;
    } else {
      this.reporForm.deviceId = window.sessionStorage.getItem("deviceId");
    }
    // console.log(this.reporForm.deviceId)
    this.getOffLineList();
  }
};
</script>
<style lang="less" scoped>
.report {
  padding: 20px;
}
</style>
